package apple.core;

import org.apache.log4j.Logger;

public class KeyboardDecoder {

   public static final String APPLE_KEYBOARD_SHORT_NAME = "Apple Keyboard";

   static Logger logger = Logger.getLogger(KeyboardDecoder.class);

   private byte asciiCode;

   private boolean strobe = false;

   private boolean keyDown = false;

   public String toString() {
      return APPLE_KEYBOARD_SHORT_NAME;
   }

   public byte getAnyKeyDownAndClearStrobe() {
      strobe = false;
      return keyDown ? (byte) 0x80 : 0x0;
   }

   public byte getKeyboardDataAndStrobe() {
      return strobe ? (byte) (asciiCode | 0x80) : asciiCode;
   }

   public void setKeyDown(boolean keyDown) {
      this.keyDown = keyDown;
   }

   public void setAsciiCodeAndStrobe(byte asciiCode) {
      this.asciiCode = (byte) (asciiCode & 0x7F);
      strobe = true;
   }
}
